package hoowin.app.wsnd.service;

import java.util.Iterator;
import java.util.List;

import hoowin.app.wsnd.dao.IDiscussionDao;
import hoowin.app.wsnd.model.Discussion;
import hoowin.basic.service.UserPool;

public class DiscussionService {
	private IDiscussionDao discussionDao;
	private UserPool up;
	public List<Discussion> getDiscussionListByStatusId(int statusId){
		List<Discussion> discussions = discussionDao.getDiscussionListByStatusId(statusId);
		Iterator<Discussion> it = discussions.iterator();
		while(it.hasNext()){
			detailizeDiscussion(it.next());
		}
		return discussions;
	}
	private void detailizeDiscussion(Discussion discussion){
		discussion.setPublisher(up.getUserById(discussion.getPublisherId()));
		discussion.setToUser(up.getUserById(discussion.getToUserId()));
	}
	public boolean addDiscussion(String content, int statusId, int publisherId, int toUserId){
		Discussion discussion = new Discussion();
		discussion.setContent(content);
		discussion.setStatusId(statusId);
		discussion.setPublisherId(publisherId);
		discussion.setToUserId(toUserId);
		return discussionDao.addDiscussion(discussion)>0;
	}
	public void setDiscussionDao(IDiscussionDao discussionDao) {
		this.discussionDao = discussionDao;
	}

	public IDiscussionDao getDiscussionDao() {
		return discussionDao;
	}
	public void setUp(UserPool up) {
		this.up = up;
	}
	public UserPool getUp() {
		return up;
	}
	
}
